import $ from 'jquery';

const doResize = (args) => {
    if (typeof args !== 'object') {
        throw new Error('参数类型必须是object');
    }
    const { width, height, header, leftBar, rightBar, content, footer } = args;
    if ((width && height) && content) {
        const headerHeight = (header && header.height()) || 0;
        const leftWidth = (leftBar && leftBar.width()) || 0;
        const rightWidth = (rightBar && rightBar.width()) || 0;
        const footerHeight = (footer && footer.height()) || 0;
        const bh = `${height - headerHeight - footerHeight}px`;
        content.css({
            height: bh,
            paddingLeft: `${leftWidth}px`,
            paddingRight: `${rightWidth}px`,
        });
        if (leftBar) {
            leftBar.css({
                height: bh,
                left: 0,
                top: `${headerHeight}px`,
            });
        }
        if (rightBar) {
            rightBar.css({
                height: bh,
                right: 0,
                top: `${headerHeight}px`,
            });
        }
    }
};
const defineSize = () => {
    const w = $(window);
    const [
        header,
        content,
        footer,
        leftBar,
        rightBar,
        width,
        height,
    ] = [
        $('#header'),
        $('#content'),
        $('#footer'),
        $('#leftBar'),
        $('#rightBar'),
        w.width(),
        w.height(),
    ];
    doResize({
        header,
        content,
        footer,
        leftBar,
        rightBar,
        width,
        height,
    });
};
export default defineSize;
